@echo off

echo ================================
echo XLSX Viewer Build Script
echo ================================
echo.

echo Checking if PyInstaller is installed...
python -c "import PyInstaller" >nul 2>&1
if errorlevel 1 (
    echo Installing PyInstaller...
    pip install pyinstaller
) else (
    echo PyInstaller is already installed.
)

echo.
echo Cleaning previous builds...
if exist "dist" (
    rmdir /s /q "dist"
)
if exist "build" (
    rmdir /s /q "build"
)

echo.
echo Building executable with PyInstaller...
pyinstaller "XLSXViewer.spec"

echo.
echo Checking build result...
if exist "dist\XLSXViewer.exe" (
    echo.
    echo ================================
    echo Build successful!
    echo ================================
    echo Executable location: %cd%\dist\XLSXViewer.exe
    
    echo.
    echo To run the program, double-click dist\XLSXViewer.exe
) else (
    echo.
    echo ================================
    echo Build failed!
    echo ================================
    echo The executable file was not found.
)

echo.
echo Build process completed.
pause